package com.zhangtong.excel.filter;

public class CommonFilter implements IFilter {
    String pre;
    String suf;

    public CommonFilter(String pre, String suf) {
        this.pre = pre;
        this.suf = suf;
    }

    @Override
    public String filter(String origin) {
        if (origin == null || origin.length() == 0) {
            return origin;
        }

        String newValue = origin;
        if (this.pre != null && this.pre.length() > 0 && origin.startsWith(this.pre)) {
            newValue = newValue.substring(this.pre.length());
        }
        if (this.suf != null && this.suf.length() > 0 && origin.endsWith(this.suf)) {
            newValue = newValue.substring(0, newValue.length() - this.suf.length());
        }

        return newValue;
    }
}
